package com.ykt.controller;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.StrKit;
import com.ykt.service.RyService;
import com.ykt.vo.ResultVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 融云语音操作
 * @author long.hua
 * @version 1.0.0
 * @since 2015-12-26 16:02
 */
public class RyController extends BaseController{

	private final  static Logger LOGGER = LoggerFactory.getLogger(RyController.class);

    private RyService ryService = enhance(RyService.class.getName(), RyService.class);


    //@Before({CommonValidator.UserIdValidator.class, RyValidator.class})
    public void accessToken(){
        String userId = getPara("userId");
        String name = getPara("name");
        String head = getPara("head");
        
        String ryToken = ryService.getAccessToken(userId, name, head);
        if(StrKit.isBlank(ryToken)){
            LOGGER.error("查询融云token为空，userId={}, name={}, head={}", userId, name, head);
            return ;
        }


        JSONObject json = JSONObject.parseObject(ryToken);
        String token = json.getString("token");

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("ryToken",token);

        returnJson(ResultVo.success(resultMap));
    }
}
